package com.by.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class JsonUtil {
    public static void getJson(HttpServletRequest request, HttpServletResponse response,Object obj){
        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Pragma","No-cache");
        response.setHeader("Cache-Control","no-cache");
        response.setDateHeader("Expires",-10);
        PrintWriter out = null;
        try{
            out = response.getWriter();
            String jsonStr = JSON.toJSONString(obj);
            out.print(jsonStr);
            out.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally{
            out.close();
        }

    }
}
